/*
 * @Author: mikey.zhaopeng 
 * @Date: 2019-01-01 19:40:50 
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2019-01-01 23:48:09
 */

import 'package:flutter/material.dart';
import '../../constants.dart' show AppColors;
import '../../widgets/swiper.dart' show TcSwiper;
import '../../widgets/discount_item.dart' show DiscountItem;

class DisCount extends StatefulWidget {
  @override
  _DisCountState createState() => _DisCountState();
}

class _DisCountState extends State<DisCount> {
  final List<Map> sliderList = [
    {'path': "assets/images/discount/slider1.png", 'gameId': 1},
    {'path': "assets/images/discount/slider2.png", 'gameId': 2},
    {'path': "assets/images/discount/slider1.png", 'gameId': 1},
    {'path': "assets/images/discount/slider2.png", 'gameId': 2},
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Color(AppColors.disCountBgColor),
      alignment: Alignment.topLeft,
      child: ListView(
        children: <Widget>[
          TcSwiper(sliderData: sliderList),
          Container(
            color: Colors.white,
            padding: const EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 15.0),
            child: Column(
              children: <Widget>[
                Container(
                  padding: const EdgeInsets.symmetric(vertical: 8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        '类型',
                        style: TextStyle(
                          fontSize: 14.0,
                          color: Color(0xff333333),
                        ),
                      ),
                      GestureDetector(
                        onTap: () {
                          print('更多页面');
                        },
                        child: Container(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 5.0, vertical: 5.0),
                          child: Text(
                            '更多',
                            style: TextStyle(
                              fontSize: 12.0,
                              color: Color(0xff999999),
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
                Container(
                  // color: Colors.r,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      _GameTypeItem(
                        bgPath: 'assets/images/discount/i@3x.png',
                        title: "仙侠",
                      ),
                      _GameTypeItem(
                        bgPath: 'assets/images/discount/j@3x.png',
                        title: "卡牌",
                      ),
                      _GameTypeItem(
                        bgPath: 'assets/images/discount/k@3x.png',
                        title: "挂机",
                      ),
                      _GameTypeItem(
                        bgPath: 'assets/images/discount/l@3x.png',
                        title: "MMO",
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            // height: 100,
            margin: const EdgeInsets.only(top: 8.0),
            color: Colors.white,
            child: Column(
              children: <Widget>[
                DiscountItem(),
                DiscountItem(),
                DiscountItem(),
                DiscountItem(),
                DiscountItem(),
                DiscountItem(),
                DiscountItem(),
                DiscountItem(),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

//四个游戏小类型
class _GameTypeItem extends StatelessWidget {
  final String bgPath;
  final String title;
  _GameTypeItem({Key key, @required this.bgPath, @required this.title})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final int width = ((MediaQuery.of(context).size.width) - 45) ~/ 4;
    final double height = width * (5 / 8);
    return GestureDetector(
      onTap: () {
        print(MediaQuery.of(context).size.width);
      },
      child: Container(
        width: width.toDouble(),
        height: height,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage(bgPath),
            fit: BoxFit.cover,
          ),
          borderRadius: BorderRadius.all(
            Radius.circular(5.0),
          ),
          color: Colors.red,
        ),
        child: Text(
          title,
          style: TextStyle(color: Colors.white, fontSize: 14.0),
        ),
      ),
    );
  }
}
